import httpClient from "./http-client";

export class PersonalCenterService {
  baseUrl = "/api/v1.0/portal/personal-center";

  async retrieve() {
    return httpClient.get(`${this.baseUrl}/retrieve`).then((res) => {
      return Promise.resolve(res.data.data);
    });
  }

  async update(user) {
    const body = {
      ...user,
    }
    return httpClient.put(`${this.baseUrl}/update`, body);
  }

  async updateAvatar(file) {
    const formData = new FormData();
    formData.append("file", file);
    return httpClient.post(`${this.baseUrl}/update-avatar`, formData, true, {
      headers: {
        "Content-Type": "multipart/form-data;charset=utf-8",
      }
    });
  }

  async removeAvatar() {
    return httpClient.post(`${this.baseUrl}/remove-avatar`);
  }

  async changePassword(param) {
    const body = {
      ...param,
    }
    return httpClient.post(`${this.baseUrl}/change-password`, body);
  }
}

const personalCenterService = new PersonalCenterService();

export default personalCenterService;